'use strict';

const Controller = require('egg/index').Controller;

class UserController extends Controller {
  /**
   * 退出登录
   */
  async logout() {
    this.ctx.session = null;
    this.ctx.sendSuccess('logout');
  }

  /**
   * 更新当前用户
   */
  async updateCurrentUser() {
    this.ctx.validate({
      user: {
        type: 'string',
        min: 4,
        max: 20,
        required: false,
      },
      pass: {
        type: 'string',
        min: 6,
        max: 20,
        required: false,
      },
      icon: {
        type: 'url',
        required: false,
      },
    });
    const data = await this.ctx.service.user.update();
    this.ctx.sendSuccess(data);
  }
}

module.exports = UserController;
